package com.bt.bodyscale.activitys;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import com.bt.bodyscale.B_MainActivity;
import com.bt.bodyscale.R;
import com.bt.bodyscale.configs.ScaleAppConfigs;
import com.ebelter.btcomlib.bases.activity.BaseActivity;
import com.ebelter.btcomlib.common.Constants;
import com.ebelter.btcomlib.utils.SpUtil;
import com.ebelter.btcomlib.utils.StatusBarUtil;
import com.ebelter.btcomlib.utils.UserSpUtil;
import com.ebelter.btcomlib.utils.log.LogUtils;


/**
 * 启动页
 */

public class B_SplashActivity extends BaseActivity implements View.OnClickListener {

    public static final String TAG = "B_SplashActivity";

    private TextView btn_sign_splash;
    private TextView btn_join_splash;

    @Override
    protected int loadLayoutById() {
        return R.layout.activity_b_splash;
    }

    @Override
    protected void initView() {
        super.initView();
        StatusBarUtil.setDarkStatusIcon(this,ScaleAppConfigs.darkStatusIcon);
        FV();
    }

    private void FV() {
        btn_sign_splash=findViewById(R.id.btn_sign_splash);
        btn_join_splash=findViewById(R.id.btn_join_splash);

        btn_sign_splash.setOnClickListener(this);
        btn_join_splash.setOnClickListener(this);
    }

    @Override
    protected void initData() {
       ScaleAppConfigs.isKgModel= SpUtil.readBoolean(Constants.IUser.IS_KG_MODEL,true);

        boolean firstInto= SpUtil.readBoolean(Constants.IUser.FIRST_INTO,true);
       // boolean firstInto= true;
        long user_id = UserSpUtil.readLong(Constants.IUser.USER_ID,-1);
        String nick_name = UserSpUtil.readString(Constants.IUser.NICK_NAME);
        String btid = UserSpUtil.readString(Constants.IUser.BT_ID);

        LogUtils.i(TAG,"----splash---A " + user_id);
        if (user_id>0&&!TextUtils.isEmpty(nick_name)&&!TextUtils.isEmpty(btid)){
            //说明已经登录了 直接登录吧
            startActivity(B_MainActivity.class);
            finish();
            return;
        }
        if (!firstInto){
            startActivity(new Intent(this, LoginActivity.class));
            finish();
            return;
        }
        SpUtil.writeBoolean(Constants.IUser.FIRST_INTO,false);

    }



    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_sign_splash://sign_in 注册
                startActivity(new Intent(this, LoginActivity.class));
                break;
            case R.id.btn_join_splash://Join us free 登录
                startActivity(new Intent(this, RegisterActivity.class));
                break;

        }
    }
}
